package org.zhouhe.tag.security;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.zhouhe.util.Constant;

import com.opensymphony.xwork2.ActionContext;

@SuppressWarnings( { "serial", "unchecked" })
public class ByMenu extends BodyTagSupport {
	private String menuId;
	private List<String> menuIdList;
	@Override
	public void doInitBody() throws JspException {
		Map<String, Object> sessionMap = ActionContext.getContext().getSession();
		menuIdList = (List<String>) sessionMap.get(Constant.SESSION_KEY_USER_MENU_ID_LIST);
	}
	
	@Override
	public int doStartTag() throws JspException {
		List<String> list = Arrays.asList(menuId.replaceAll(" ", "").split(","));
		if (menuIdList != null && menuIdList.containsAll(list)) {
			return EVAL_BODY_INCLUDE;
		}
		return SKIP_BODY;
	}

	public void setMenuId(String menuId) {
		this.menuId = menuId;
	}

	public String getMenuId() {
		return menuId;
	}

	public void setMenuIdList(List<String> menuIdList) {
		this.menuIdList = menuIdList;
	}

	public List<String> getMenuIdList() {
		return menuIdList;
	}
}
